﻿#region Copyright (c) Lokad 2010
// This code is released under the terms of the new BSD licence.
// URL: http://www.lokad.com/
#endregion
using System.Collections.Generic;
using System.Linq;
using Lokad.Monitoring.Persistence.Entities;
using NHibernate.Linq;

namespace Lokad.Monitoring.Persistence.Repositories
{
    public class UserRepository : BaseRepository
    {
        public IList<User> List()
        {
            return
                (from e in Session.Linq<User>()
                 orderby e.Id
                 select e).ToList();
        }

        public void Create(User user)
        {
            using (var trans = Session.BeginTransaction())
            {
                Session.Save(user);
                trans.Commit();
            }
        }

        public void Delete(long id)
        {
            using (var trans = Session.BeginTransaction())
            {
                var db = Session.Get<User>(id);
                Session.Delete(db);
                trans.Commit();
            }
        }
    }
}
